package com.quick.domain;

import lombok.Synchronized;

/**
 * @Synchronized注解类似Java中的Synchronized 关键字，但是可以隐藏同步锁。
 * Created by wangxin332 on 2018/5/13.
 */
public class UseSynchronized {
    private final Object readLock = new Object();
    @Synchronized
    public static void hello(){
        System.out.println("world");
    }

    @Synchronized("readLock")
    public void foo(){
        System.out.println("bar");
    }

    //等同于

    public static final Object $LOCK = new Object[0];
    private final Object readLock1 = new Object();

    public static void hello1() {
        synchronized($LOCK) {
            System.out.println("world");
        }
    }

    public void foo1() {
        synchronized(readLock1) {
            System.out.println("bar");
        }
    }
}
